package com.monster.mechanic.dbmodel.dao;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.monster.mechanic.dbmodel.dto.ClientDTO;
import com.monster.mechanic.dbmodel.hibernate.HibernateUtil;

public class ClientDAO {
	
	public Long insert(ClientDTO clientDTO) throws HibernateException {
		Transaction tx = null;
		try {
			Session session = HibernateUtil.getInstance().openSession();
			tx = session.beginTransaction();
			Long id = (Long)session.save(clientDTO);
			tx.commit();
			return id;
		} catch(HibernateException e) {
			if (tx != null) {
				tx.rollback();
			}
			throw e;
		}
		finally {
			HibernateUtil.close();
		}
	}

}
